import pymysql
import pandas
from numpy import *
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.metrics.pairwise import linear_kernel
mysql = pymysql.connect ("10.100.175.57", "root","gly123", "movie")
sql=('select * from movie_if')
cursor=mysql.cursor(pymysql.cursors.DictCursor)
cursor.execute(sql)
movie=cursor.fetchall()
pandas.DataFrame(movie).to_csv('movie_new.csv')
movies=pandas.io.parsers.read_csv('movie_new.csv')
tfidf=TfidfVectorizer()
tfidf_matrix=tfidf.fit_transform(movies['type_name'])
cosine_sim=linear_kernel(tfidf_matrix,tfidf_matrix)
indices=pandas.Series(movies.index,index=movies['movie_name']).drop_duplicates()
def get_recommendation(title,consine_sim=cosine_sim):
    idx=indices[title]
    sim_scores=list(enumerate(cosine_sim[idx]))
    sim_scores=sorted(sim_scores,key=lambda x:x[1],reverse=True)
    sim_scores=sim_scores[1:11]
    movie_indices=[i[0]for i in sim_scores]
    return movies['movie_name'].iloc[movie_indices]
print(get_recommendation('X战警'))